package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.wemeida.dtos.ArticleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {
    @Autowired
    private ApArticleService apArticleService;

    /**
     * 保存App文章
     */
    @PostMapping("/save")
    public ResponseResult<Long> saveApArticle(@RequestBody ArticleDto dto){
        return ResponseResult.okResult(apArticleService.saveApArticle(dto));
    }

    /**
     * 查询所有文章
     */
    @GetMapping("/findApArticles")
    public ResponseResult<List<ApArticle>> findApArticles(){
        return ResponseResult.okResult(apArticleService.list());
    }

    /**
     * 根据id查询App文章
     */
    @GetMapping("/findById/{id}")
    public ResponseResult<ApArticle> findById(@PathVariable("id") Long id){
        return ResponseResult.okResult(apArticleService.getById(id));
    }

    /**
     * 模拟扩展接口
     */
    @GetMapping("/findArticle/{id}")
    public ResponseResult<ApArticle> findArticle(@PathVariable("id") Long id){
        return ResponseResult.okResult(apArticleService.getById(id));
    }
}
